package uk.ac.rothamsted.misc;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import uk.ac.rothamsted.utils.DefaultSuppliers;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;

public class BasicSnippets {
	
	@SuppressWarnings("unused")
	public static void nothing() throws Exception{
		//Reading a file
		BufferedReader br = new BufferedReader(new FileReader(""));
		String line;
		while((line = br.readLine()) != null){
			// Split line on tab
			String data [] = line.split("\t");
		}
		br.close();
		
		//Writing a file
		String [] lines = new String []{};
		BufferedWriter bw = new BufferedWriter(new FileWriter(""));
		for(String l : lines){
			bw.write(l);
			bw.write("\n");
		}
		bw.flush();
		bw.close();
		
		//iterating over all key-value pairs
		Map<String, String> map = new HashMap<String, String>();
		for(Entry<String, String> ent : map.entrySet()){
			ent.getKey(); ent.getValue();
			//etc...
		}
		
		//Google collections -  set multimap creation
		SetMultimap<String, String> setMultimap =  Multimaps.newSetMultimap(Maps.<String, Collection<String>> newHashMap(), DefaultSuppliers.set(String.class));
		
		//Google collections -  list multimap creation
		ListMultimap<String, String> listMultimap =  ArrayListMultimap.create();
		
		//Java regex
		String stringToSearchIn ="";
		Pattern p = Pattern.compile("");
		// check a string for a match
		Matcher matcher = p.matcher(stringToSearchIn);
		while(matcher.find()){
			String found = matcher.group();
		}
		
		//Custom sorting
		List<String> list = new ArrayList<String>();
		Collections.sort(list, new Comparator<String>(){
			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				return 0;
			}
		});
		
		
	}
}
